﻿using System;
using System.ComponentModel;
using System.Xml;

namespace Moonlite.Data.EditorInterop
{
    [DefaultProperty("Index")]
    [DisplayName("Value")]
    public class CameraValue : IDeserializedObject, IRepresentedAsProperty
    {
        private string index;
        private string value;
        private DeserializedObjectCollection children = new DeserializedObjectCollection();

        public string Index
        {
            get { return index; }
        }

        public string Value
        {
            get { return value; }
        }

        public DeserializedObjectCollection Children
        {
            get { return children; }
        }

        internal static CameraValue Parse(XmlNode node)
        {
            string index = "";
            string value = "";
            foreach (XmlAttribute attribute in node.Attributes)
            {
                switch (attribute.Name.ToLower())
                {
                    case "index":
                        index = attribute.Value;
                        break;
                    case "value":
                        value = attribute.Value;
                        break;
                }
            }

            return new CameraValue(index, value);
        }

        internal CameraValue(string index, string value)
        {
            if (string.IsNullOrEmpty(index))
            {
                throw new ArgumentNullException("index");
            }

            if (string.IsNullOrEmpty(value))
            {
                throw new ArgumentNullException("value");
            }

            this.index = index;
            this.value = value;
        }
    }
}
